<%= stylesheet_link_tag "form" -%>

<%= template_error_messages_for 'share_file' %>

<%= hidden_field_tag 'owner_name', params[:owner_name] %>
<%= hidden_field_tag 'owner_symbol', params[:owner_symbol] %>
<%= hidden_field 'share_file', 'owner_symbol' %>

<div class="input_line">
  <div class="input_label" style="height: 30px;">公開日付</div>
  <div class="input_value">
    <p><%= datetime_select 'share_file', 'date', :use_month_numbers => true -%></p>
    <p><a href="#" onclick="setCurrentDatetime('share_file', 'date');">[現在時刻を設定]</a>
  </div>
  <div style="clear: left"></div>
</div>

<div class="input_line">
  <div class="input_label">保存場所</div>
  <div class="input_value"><%= h(owner_name) -%></div>
  <div style="clear: left"></div>
</div>

<div class="input_line">
  <div class="input_label" style="height: 30px;" id="input_label_publication">公開範囲</div>
  <div class="input_value" id="input_value_publication"><table><tr><td>
    <% display_type = (@share_file.owner_is_public? ? "" : "none") %>
    <span style="display:<%= display_type %>">
      <%= radio_button_tag("publication_type", "public", params[:publication_type] == "public", :id=>"publication_type_public") -%>全体に公開
    </span>
    <%= radio_button_tag("publication_type", "private", params[:publication_type] == "private", :id=>"publication_type_private") -%><%= show_private_value share_file -%>
    <%= radio_button_tag("publication_type", "protected", params[:publication_type] == "protected", :id=>"publication_type_protected") %>直接指定

    <%= render :partial => "shared/symbol_autocomplete_field", :locals => {:publication_symbols_value => params[:publication_symbols_value], :editor_symbols_value => params[:editor_symbols_value], :edit_checkbox => false } %>
    </td></tr></table>
  </div>
  <div style="clear: left"></div>
</div>

<div class="input_line">
  <div class="input_label">タグ</div>
  <div class="input_value"><%= text_field 'share_file', 'category', :size => '60', :value => @share_file.comma_category %>
    <div id="category_box" style="display:none;">
      <div id="candidates_list"><p>foo,barの形で複数指定できます</p></div>
      <div style="font-size:10pt; font-weight:bold;">タグ：</div><div id="tags_list" style="margin-bottom:5px;"></div>
      <div style="font-size:10pt; font-weight:bold;">人気のタグ：</div><div id="user_tags_list" style="margin-bottom:5px;"></div>
    </div>
  </div>
  <div style="clear: left"></div>
</div>

<div class="input_line">
  <div class="input_label">コメント</div>
  <div class="input_value"><%= text_field 'share_file', 'description', :size =>60 %></div>
  <div style="clear: left"></div>
</div>

<script language='javascript' type='text/javascript'>
//<![CDATA[
$j(function() {
    // TODO 下のメソッド二つはおそらくエントリの部分でも使えそう。
    var changePublicationType = function() {
        if ($j('#publication_type_protected:checked').length > 0) {
            $j('#publication_symbols_space').show();
            $j('#publication_symbol').focus();
        } else {
            $j('#publication_symbols_space').hide();
        }
    };

    var checkPublicationType = function() {
        var publicationSymbolsValue = $j('#publication_symbols_value');
        if ($j('#publication_type_public:checked').length > 0) {
            publicationSymbolsValue.val('');
        }
        if ($j('#publication_type_protected:checked').length > 0) {
            if ( publicationSymbolsValue.val() == '' ) {
                if (confirm("ユーザの指定がされていません。\r\nこのままだと、「全体に公開」になりますがよろしいですか？")) {
                    $j('#publication_type_public').attr('checked', true);
                    changePublicationType();
                } else {
                    return false;
                }
            }
        }
        return true;
    };

    $j('#publication_type_public, #publication_type_protected, #publication_type_private')
    .click(function() {
        changePublicationType();
    });

    $j('#share_file_form')
    .submit(function() {
        if (!checkPublicationType()) {
            return false;
        }
    });

    changePublicationType();

    $j('#share_file_category').focus(function() {
        showCategoryBox();
    });

    $j('#share_file_description').focus(function() {
        hideCategoryBox();
    });

    var tags = new Array(<%= categories_hash[:mine].map{|str| ("'#{str}'")}.join(',') %>);
    var userTags = new Array(<%= categories_hash[:user].map{|str| ("'#{str}'")}.join(',') %>);

    $j('#tags_list').append(createTagsLink(tags));
    $j('#user_tags_list').append(createTagsLink(userTags));

    // タグ処理
    $j('#share_file_category').jTagging($j('#tags_list'));
    $j('#share_file_category').jTagging($j('#user_tags_list'));
});
//]]>
</script>
